package com.hu.zhcc.shiro.controller.Lixueseng520;

import com.hu.zhcc.common.entity.Page;
import com.hu.zhcc.shiro.entity.bo.Lixueseng520.LxsDisease;
import com.hu.zhcc.shiro.service.Lixueseng520.DiseaseService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("disease")
public class DiseaseController {
    @Autowired
    private DiseaseService diseaseService;

    // 查询
    @GetMapping("")
    public Page<LxsDisease> getDiseaseList(String encode,Integer offset,Integer limit){
        Map map = new HashMap();
        if (!StringUtils.isBlank(encode)){
            map.put("encode",encode);
        }
        return diseaseService.findDiseaseByPrimary(map,offset,limit);
    }
    // 添加
    @PostMapping("add")
    public int saveDisease(@RequestBody LxsDisease disease){
        diseaseService.insertSelective(disease);
        disease.setEncode("JB000"+disease.getId());
        return diseaseService.updateByPrimaryKeySelective(disease);
    }
    // 修改
    @PutMapping("/{id}")
    public int getDiseaseById(@PathVariable("id") int id,@RequestBody LxsDisease disease){
        return diseaseService.updateByPrimaryKeySelective(disease);
    }
    // 删除
    @DeleteMapping("/{id}")
    public int removeDisease(@PathVariable("id") int id){
        return diseaseService.deleteByPrimaryKey(id);
    }
}
